package com.rop.ecommerce.advice;

import com.rop.ecommerce.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @Title: GlobalExceptionAdvice
 * @Author Rop
 * @Date 2023/10/3 10:23
 * @description: 全局异常处理
 */

@Slf4j
@RestControllerAdvice
public class GlobalExceptionAdvice {

    public CommonResponse<String> handlerCommerceException(HttpServletRequest req, Exception e) {

        CommonResponse<String> response = new CommonResponse<>(-1, "business error");

        response.setData(e.getMessage());

        log.error("commerce service has error: [{}]", e.getMessage(), e);

        return response;
    }
}
